//
//  HomeTableCell.m
//  GoldOperationClient
//
//  Created by yaxue wang on 16/8/4.
//  Copyright © 2016年 展鸿科技. All rights reserved.
//

#import "HomeTableCell.h"
#import "HomeModel.h"
@interface HomeTableCell()
@property (nonatomic, strong) UIView *coverView;
//@property (nonatomic, strong) UIImageView *headImg;
@property (nonatomic, strong) UILabel *titleLab;
@property (nonatomic, strong) UILabel *timeLab;
@property (nonatomic, strong) UIButton *typeBtn;
@property (nonatomic, strong) UIButton *replyBtn;
@property (nonatomic, strong) UILabel *nameLab;
@property (nonatomic, strong) UILabel *contexLab;
@property (nonatomic, strong) UILabel *clientLab;
@property (nonatomic, strong) UILabel *stateLab;
@property (nonatomic, strong) UILabel *line;

@end
@implementation HomeTableCell
- (void)initView{
    [super initView];
    self.backgroundColor =[UIColor clearColor];
    
    self.coverView =[[UIView alloc]initWithFrame:CGRectMake(25, 0, WindowWidth-50, 145)];
    [self addSubview:self.coverView];
    self.coverView.backgroundColor =[UIColor whiteColor];
    self.coverView.layer.masksToBounds =YES;
    self.coverView.layer.cornerRadius =7;


    
    self.stateLab = [[UILabel alloc] init];
    [self.coverView addSubview:self.stateLab];
    [self.stateLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.coverView).offset(-15);
        make.top.equalTo(self.coverView).offset(10);
        make.width.equalTo(@(40));
        make.height.equalTo(@(20));
        
    }];
    self.stateLab.textColor =[UIColor whiteColor];
    self.stateLab.textAlignment=NSTextAlignmentCenter;
    self.stateLab.font =F(10);

    self.titleLab =[[UILabel alloc]init];
    [self.coverView addSubview:self.titleLab];
    [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.coverView).offset(15);
        make.top.equalTo(self.coverView).offset(10);
        make.right.equalTo(self.stateLab.mas_left).offset(-5);
    }];
    self.titleLab.textColor = C(@"454545");
    self.titleLab.font = F(11);
    
    
    self.clientLab = [[UILabel alloc]init];
    [self.coverView addSubview:self.clientLab];
    [self.clientLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.titleLab);
        make.top.equalTo(self.titleLab.mas_bottom).offset(10);
        make.right.equalTo(self.coverView).offset(-10);
    }];
    self.clientLab.textColor =C(@"a19d9d");
    self.clientLab.font =F(10);

 

    self.nameLab = [[UILabel alloc]init];
    [self.coverView addSubview:self.nameLab];
    [self.nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.titleLab);
        make.top.equalTo(self.clientLab.mas_bottom).offset(10);
        make.right.equalTo(self.coverView).offset(-10);
    }];
    self.nameLab.textColor =C(@"a19d9d");
    self.nameLab.font =F(10);
    
    
    self.contexLab =[[UILabel alloc]init];
    [self.coverView addSubview:self.contexLab];
    [self.contexLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.titleLab);
        make.top.equalTo(self.nameLab.mas_bottom).offset(10);
        make.width.equalTo(self.titleLab);
        
    }];
    self.contexLab.textColor =C(@"a19d9d");
    self.contexLab.font =F(10);
    
    self.line =[[UILabel alloc]init];
    [self.coverView addSubview:self.line];
    [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.coverView).offset(15);
        make.top.equalTo(self.coverView.mas_bottom).offset(-43);
        make.right.equalTo(self.coverView).offset(-15);
        make.height.equalTo(@(0.5));
    }];
    self.line.backgroundColor =C(@"e8e7e7");
    
    self.typeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.coverView addSubview:self.typeBtn];
    [self.typeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.line.mas_bottom).offset(12);
        make.right.equalTo(self.coverView).offset(-15);
        make.height.equalTo(@(20));
        make.width.equalTo(@(55));
    }];
    self.typeBtn.layer.masksToBounds=YES;
    self.typeBtn.layer.cornerRadius =5;
    self.typeBtn.layer.borderColor =Yellow.CGColor;
    self.typeBtn.layer.borderWidth=0.5;
    [self.typeBtn setTitleColor:Yellow forState:UIControlStateNormal];
    self.typeBtn.titleLabel.font =F(10);
    [self.typeBtn bk_addEventHandler:^(id sender) {
        if (self.btnActionBlock) {
            self.btnActionBlock(self);
        }
    } forControlEvents:UIControlEventTouchUpInside];
    self.typeBtn.hidden=YES;
    
    self.replyBtn =[UIButton buttonWithType:UIButtonTypeCustom];
    [self.coverView addSubview:self.replyBtn];
    [self.replyBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.typeBtn);
        make.right.equalTo(self.typeBtn.mas_left).offset(-10);
        make.height.equalTo(@(20));
        make.width.equalTo(@(55));
    }];
    [self.replyBtn setTitle:@"补充设备" forState:UIControlStateNormal];

    self.replyBtn.layer.masksToBounds=YES;
    self.replyBtn.layer.cornerRadius =5;
    self.replyBtn.layer.borderColor =Yellow.CGColor;
    self.replyBtn.layer.borderWidth=0.5;
    [self.replyBtn setTitleColor:Yellow forState:UIControlStateNormal];
    self.replyBtn.titleLabel.font =F(10);
    [self.replyBtn bk_addEventHandler:^(id sender) {
        if (self.goReplyActionBlock) {
            self.goReplyActionBlock(self);
        }
    } forControlEvents:UIControlEventTouchUpInside];
    self.replyBtn.hidden=YES;

    self.timeLab =[[UILabel alloc]init];
    [self.coverView addSubview:self.timeLab];
    [self.timeLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.coverView).offset(15);
        make.top.equalTo(self.line.mas_bottom).offset(14);
        make.right.equalTo(self.replyBtn.mas_left).offset(-5);
    }];
    self.timeLab.font =F(10);
    self.timeLab.textColor =[UIColor colorFromHexString:@"a19d9d"];
    
    [self setSelectionStyle:UITableViewCellSelectionStyleNone];

    
}
- (void)setModel:(id)model{
    

    
    HomeModel *order = model;
    
    if (order.H_order_number ==nil||[order.H_order_number isEqualToString:@""]) {
        self.titleLab.text =@"报修单号：";
        
    }else
    {
        self.titleLab.text =[NSString stringWithFormat:@"报修单号：%@",order.H_order_number];
    }
    if (order.H_order_number ==nil||[order.H_order_number isEqualToString:@""]) {
        self.clientLab.text =@"报修客户：";
        
    }else
    {

        self.clientLab.text =[NSString stringWithFormat:@"报修客户：%@",order.H_bankname];
    }
    
    if ((order.H_name ==nil||[order.H_name isEqualToString:@""])&&(order.H_type_cd ==nil||[order.H_type_cd isEqualToString:@""])) {
        self.nameLab.text =[NSString stringWithFormat:@"%@%@",order.H_type_cd,order.H_name];
        self.nameLab.hidden=YES;
       self.replyBtn.hidden=NO;

        
    }else if ((order.H_name ==nil||[order.H_name isEqualToString:@""])||(order.H_type_cd ==nil||[order.H_type_cd isEqualToString:@""])) {
        
        if(order.H_name ==nil||[order.H_name isEqualToString:@""]){
            self.nameLab.text =[NSString stringWithFormat:@"%@",order.H_type_cd];
            self.nameLab.hidden=NO;
            self.replyBtn.hidden=NO;
        }else{
            self.nameLab.text =[NSString stringWithFormat:@"%@",order.H_name];
            self.nameLab.hidden=NO;
           self.replyBtn.hidden=NO;

        }
        
    }else
    {
        self.nameLab.hidden=NO;
        self.replyBtn.hidden=YES;
        self.nameLab.text =[NSString stringWithFormat:@"%@ %@",order.H_type_cd,order.H_name];
    }
    if ([order.H_textFlg isEqualToString:@"0"]) {
        self.contexLab.text=@"(非文字报修)";
        self.contexLab.textColor=Yellow;

    }else
    {
        self.contexLab.text=order.H_textdescribe;

    }
    NSString  *a = order.H_created;
    if (a ==nil||[a isEqualToString:@""]) {
        self.timeLab.text =@"";
        
    }else
    {
        self.timeLab.text =order.H_created;
    }
     if (order.H_state ==nil||[order.H_state isEqualToString:@""])
     {
     
     }else
     {
         NSInteger num=[order.H_state integerValue];
         
     
         if(num ==1)
         {
             //待接单 分配
            //显示接单按钮
             self.typeBtn.hidden=NO;
             [self.typeBtn setTitle:@"接单" forState:UIControlStateNormal];
     
     
     
         } else if(num ==2)
         {
             //待处理
            //显示开始处理按钮
             self.typeBtn.hidden=NO;
             [self.typeBtn setTitle:@"开始" forState:UIControlStateNormal];
     
     
         }else if(num==4||num==5){
             //处理中
            //显示标记完成按钮
             //待挂起
            	//一样---> 显示标记完成按钮
             self.typeBtn.hidden=NO;
             [self.typeBtn setTitle:@"标记完成" forState:UIControlStateNormal];
         }else if(num==6){
             //已挂起
            //显示恢复按钮
             self.typeBtn.hidden=NO;
             [self.typeBtn setTitle:@"恢复" forState:UIControlStateNormal];
         }else
         {
             self.typeBtn.hidden=YES;
         }
         
         
         if(num==0||num ==3||num==97||num==99||num==98)
         {
             //待确认 为空
             self.stateLab.text=@"";
             self.stateLab.backgroundColor =[UIColor clearColor];
         }else if (num==4||num==5) {
             // 处理中
             self.stateLab.text=@"处理中";
             self.stateLab.backgroundColor =Yellow;
         }else if(num==1)
         {
             self.stateLab.text=@"待接单";
             self.stateLab.backgroundColor =C(@"29b404");
         }else if(num==2)
         {
             self.stateLab.text=@"待处理";
             self.stateLab.backgroundColor =C(@"29b404");
         }else if(num==6)
         {
             self.stateLab.text=@"挂起中";
             self.stateLab.backgroundColor =Yellow;
         }

     }
    
   
    
}

@end
